package com.mc.moring.widge;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

public class VerticalDashedLineView extends View {

    private Paint paint;
    private Path path;

    public VerticalDashedLineView(Context context) {
        super(context);
        init();
    }

    public VerticalDashedLineView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public VerticalDashedLineView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(0xFFDADADA); // 设置线条颜色
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(5); // 设置线条宽度
        paint.setPathEffect(new DashPathEffect(new float[]{10, 10}, 0)); // 设置虚线样式
        path = new Path();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = getWidth();
        int height = getHeight();
        path.reset();
        path.moveTo(0, 0);
        path.lineTo(0, height);
        canvas.drawPath(path, paint);
    }
}
